<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>IntersectionObserver</title>
</head>
<body>
    <div style="height: 500px;width: 200px;overflow:scroll">
        <div style="position: relative; height: 2000px">
            <div id="red" style="position: absolute; top: 0px; height: 200px; width: 100%; background: red;"></div>
            <div id="green" style="position: absolute; top: 750px; height: 200px; width: 100%; background: green;"></div>
            <div id="blue" style="position: absolute; top: 1500px; height: 200px; width: 100%; background: blue;"></div>
        </div>
    </div>
    <script>
        let intersectionObserver = new IntersectionObserver(_ => {
            console.log("red")
        }, {
            threshold: 0
        })
        intersectionObserver.observe(document.getElementById("red"))

        let intersectionObserver1 = new IntersectionObserver(_ => {
            console.log("green")
        }, {
            threshold: 1
        })

        intersectionObserver1.observe(document.getElementById("green"))
    </script>
</body>
</html>